package net.lab1024.sa.user.module.business.course.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.sa.common.common.domain.PageResult;
import net.lab1024.sa.common.common.util.SmartPageUtil;
import net.lab1024.sa.user.module.business.course.dao.PartnerDao;
import net.lab1024.sa.user.module.business.course.domain.entity.PartnerEntity;
import net.lab1024.sa.user.module.business.course.domain.form.PartnerQueryForm;
import net.lab1024.sa.user.module.business.course.domain.vo.PartnerVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 合作方 Service
 *
 * @Author jabari
 * @Date 2023-08-05 16:39:22
 * @Copyright 51dev.cn
 */

@Service
public class PartnerService {

    @Autowired
    private PartnerDao partnerDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<PartnerVO> queryPage(PartnerQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<PartnerVO> list = partnerDao.queryPage(page, queryForm);
        PageResult<PartnerVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    public Map<Integer,PartnerVO> getPartners(List<Integer> partnerIds){
        List<PartnerEntity> partnerEntities = partnerDao.selectBatchIds(partnerIds);
        Map<Integer, PartnerVO> partnerEntityMap = partnerEntities.stream().collect(Collectors.toMap(PartnerEntity::getPartnerId, partner -> {
            PartnerVO partnerVO=new PartnerVO();
            BeanUtils.copyProperties(partner,partnerVO);
            return partnerVO;
        }));
        return partnerEntityMap;
    }


}
